package com.sys.listener;

import com.dto.sys.EmployeeDto;
import com.sys.EmployeeEvent;
import com.sys.dao.EventEmployeeMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author xufan
 */
@Component
public class EmployeeListener implements ApplicationListener<EmployeeEvent> {
    private static final Logger logger = LoggerFactory.getLogger(EmployeeListener.class);
    @Resource
    private EventEmployeeMapper eventEmployeeMapper;

    @Override
    @Async("asyncTaskExecutor")
    public void onApplicationEvent(EmployeeEvent employeeEvent) {
        Map<String, Object> param = (Map<String, Object>) employeeEvent.getSource();
        if (param != null) {
            logger.info("测试异步事件" + param.get("employeeName"));
            EmployeeDto employeeDto = new EmployeeDto();
            employeeDto.setEmployeeId(String.valueOf(param.get("employeeId")));
            Map<String, Object> mapEmployee = eventEmployeeMapper.getEmployeeById(employeeDto);
            logger.info("异步事件，员工姓名：" + mapEmployee.get("name"));

        }
    }
}
